package cn.scut.srp.controller.common;

import cn.scut.srp.model.BaseResponse;
import cn.scut.srp.model.ResponseCode;
import cn.scut.srp.service.PublicService;
import cn.scut.srp.service.StudentService;
import cn.scut.srp.utils.ResponseUtil;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/common")
public class LoginController {

    @Autowired
    private PublicService service;

    @Operation(summary = "CommonController",description = "登录接口，返回token")
    @PostMapping("/login")
    public BaseResponse<ResponseCode> login(@RequestBody Map<String, Object> loginEntity){
        String username = (String) loginEntity.get("username");
        String password = (String) loginEntity.get("password");

        if(username == null || password == null){
            return ResponseUtil.noInfo("传入了空的用户名或密码!");
        }
        return service.login(username, password);
    }
}
